/*
 * Copyright (c) [2020-2021] [http://www.zxpnet.com]
 */

package com.zxp.springboot.controller;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zxp.common.constant.module.CacheConstants;
import com.zxp.springboot.pojo.HelloUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author zxp
 * @date 2021/6/21 18:39
 */
@Controller
public class BeetlDemoController {

    @GetMapping("/demo")
    public String demo(Model model){
        ModelAndView view = new ModelAndView();

        HashMap<Object, Object> map = Maps.newHashMap();
        map.put("aa", "aa");
        map.put("long", 12345649687987354L);
        map.put("uuid", IdUtil.randomUUID());
        map.put("cache", CacheConstants.CLIENT_DETAILS_KEY);

        HelloUser helloUser = new HelloUser();
        helloUser.setId(1221324313544350L);
        helloUser.setUsername("jim");
        helloUser.setAge(123);
        helloUser.setSalary(new BigDecimal("1523.6501"));
        helloUser.setCreateTime(RandomUtil.randomDay(-365*5,365*5));
        helloUser.setBirthday(LocalDate.now());
        helloUser.setUpdateTime(LocalDateTime.now());
        helloUser.setParent(null);
        map.put("helloUser", helloUser);
        ArrayList<HelloUser> users = Lists.newArrayList();

        users.add(helloUser);

        for (int i = 0; i < 10; i++) {
            HelloUser u = new HelloUser();
            u.setId(RandomUtil.randomLong(12));
            u.setUsername(RandomUtil.randomNumbers(6));
            u.setAge(RandomUtil.randomInt(10,60));
            u.setSalary(new BigDecimal(RandomUtil.randomDouble(3000,50000,2, RoundingMode.HALF_UP)));
            u.setCreateTime(RandomUtil.randomDay(-365*5,365*5));
            u.setBirthday(LocalDate.now());
            u.setUpdateTime(LocalDateTime.now());
            u.setParent(users.get(i));

            users.add(u);
        }

        map.put("listUser", users);
        model.addAttribute("map",map);
        System.out.println(112);
        return "demo.html";
    }
}
